home *** CD-ROM | disk | FTP | other *** search
Wrap
package { import flash.display.*; import flash.events.*; import flash.filters.*; import flash.geom.*; import flash.net.*; import flash.system.*; import flash.text.*; import flash.utils.*; import flash.xml.*; public class textfield extends Sprite { private var krpano:krpano_as3_interface = null; public var pluginpath:String = null; public var pluginobj:Object = null; public var bg:Shape = null; public var txt:TextField = null; public var txt_width:int = 400; public var txt_height:int = 300; public function textfield() { var txt:TextField = null; var f:TextFormat = null; var resizefu:Function = null; super(); if(stage == null) { this.addEventListener(Event.ADDED_TO_STAGE,this.startplugin); this.addEventListener(Event.UNLOAD,this.stopplugin); } else { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; txt = new TextField(); txt.textColor = 16777215; txt.selectable = false; txt.htmlText = "krpano " + "1.0.8.12" + "\n\n" + "<b>textfield plugin</b>" + "\n\n" + "(build " + "CUSTOM" + ")"; f = new TextFormat(); f.font = "_sans"; f.size = 14; txt.autoSize = f.align = "center"; txt.setTextFormat(f); addChild(txt); resizefu = function(param1:Event):void { txt.x = (stage.stageWidth - txt.width) / 2; txt.y = (stage.stageHeight - txt.height) / 2; }; stage.addEventListener(Event.RESIZE,resizefu); resizefu(null); } } private function startplugin(param1:Event) : void { this.removeEventListener(Event.ADDED_TO_STAGE,this.startplugin); if(this.krpano == null) { this.krpano = krpano_as3_interface.getInstance(); if(this.krpano.get("version") < "1.0.8") { this.krpano.call("error(textfield plugin - wrong krpano version - min. 1.0.8 needed);"); return; } this.krpano.addPluginEventListener(this,krpano_as3_interface.PLUGINEVENT_REGISTER,this.registerEvent); this.krpano.addPluginEventListener(this,krpano_as3_interface.PLUGINEVENT_RESIZE,this.resizeEvent); this.krpano.addPluginEventListener(this,krpano_as3_interface.PLUGINEVENT_UPDATE,this.updateEvent); } } private function stopplugin(param1:Event) : void { this.txt.removeEventListener(TextEvent.LINK,this.link_event); this.krpano.removePluginEventListener(this,krpano_as3_interface.PLUGINEVENT_REGISTER,this.registerEvent); this.krpano.removePluginEventListener(this,krpano_as3_interface.PLUGINEVENT_RESIZE,this.resizeEvent); this.krpano.removePluginEventListener(this,krpano_as3_interface.PLUGINEVENT_UPDATE,this.updateEvent); removeChild(this.bg); this.bg = null; removeChild(this.txt); this.txt = null; this.krpano = null; } private function registerEvent(param1:DataEvent) : void { this.pluginpath = param1.data; this.pluginobj = this.krpano.get(this.pluginpath); this.pluginobj.registerattribute("html",""); this.pluginobj.registerattribute("css",""); this.pluginobj.registerattribute("autosize","none"); this.pluginobj.registerattribute("wordwrap",true); this.pluginobj.registerattribute("background",true); this.pluginobj.registerattribute("backgroundcolor",16777215); this.pluginobj.registerattribute("backgroundalpha",1); this.pluginobj.registerattribute("border",false); this.pluginobj.registerattribute("bordercolor",0); this.pluginobj.registerattribute("borderwidth",1); this.pluginobj.registerattribute("roundedge",0); this.pluginobj.registerattribute("selectable",true); this.pluginobj.registerattribute("glow",0); this.pluginobj.registerattribute("glowcolor",16777215); this.pluginobj.registerattribute("blur",0); this.pluginobj.registerattribute("shadow",0); this.pluginobj.registerattribute("textglow",0); this.pluginobj.registerattribute("textglowcolor",16777215); this.pluginobj.registerattribute("textblur",0); this.pluginobj.registerattribute("textshadow",0); this.pluginobj.update = this.updateHTML; this.bg = new Shape(); this.txt = new TextField(); this.txt.htmlText = ""; this.txt.multiline = true; this.txt.wordWrap = true; this.txt.border = false; this.txt.background = false; this.txt.condenseWhite = true; this.txt.width = this.txt_width; this.txt.height = this.txt_height; this.txt.addEventListener(TextEvent.LINK,this.link_event); this.addChild(this.bg); this.addChild(this.txt); this.updateSTYLE(); this.updateHTML(); } private function updateEvent(param1:DataEvent) : void { var _loc2_:* = "." + String(param1.data) + "."; var _loc3_:String = ".html.css."; var _loc4_:String = ".autosize.wordwrap.background.backgroundcolor.backgroundalpha.border.bordercolor.borderwidth.roundedge.selectable.glow.blur.shadow.textglow.textblur.textshadow."; if(_loc3_.indexOf(_loc2_) >= 0) { this.updateHTML(); } else if(_loc4_.indexOf(_loc2_) >= 0) { this.updateSTYLE(); } } private function resizeEvent(param1:DataEvent) : void { var _loc3_:int = 0; var _loc4_:int = 0; var _loc2_:String = param1.data; _loc3_ = parseInt(_loc2_); _loc4_ = parseInt(_loc2_.slice(_loc2_.indexOf("x") + 1)); this.txt.width = _loc3_; this.txt.height = _loc4_; this.txt_width = _loc3_; this.txt_height = _loc4_; this.updateSTYLE(); } private function link_event(param1:TextEvent) : void { this.krpano.call(param1.text,null,this.pluginobj); } private function updateSTYLE() : void { switch(String(this.pluginobj.autosize).toLowerCase()) { case "true": case "auto": case "left": this.txt.autoSize = "left"; break; case "center": this.txt.autoSize = "center"; break; case "right": this.txt.autoSize = "right"; break; case "none": default: this.txt.autoSize = "none"; } this.txt.wordWrap = this.pluginobj.wordwrap; this.txt.selectable = this.pluginobj.selectable; this.bg.alpha = this.pluginobj.backgroundalpha; this.bg.graphics.clear(); if(Boolean(this.pluginobj.background) || Boolean(this.pluginobj.border)) { if(this.pluginobj.borderwidth > 0) { this.bg.graphics.lineStyle(this.pluginobj.borderwidth,this.pluginobj.bordercolor); } if(this.pluginobj.background) { this.bg.graphics.beginFill(this.pluginobj.backgroundcolor); } if(this.pluginobj.roundedge <= 0) { this.bg.graphics.drawRect(0,0,this.txt_width,this.txt_height); } else { this.bg.graphics.drawRoundRect(0,0,this.txt_width,this.txt_height,this.pluginobj.roundedge); } } var _loc1_:Array = new Array(); if(this.pluginobj.glow > 0) { _loc1_.push(new GlowFilter(this.pluginobj.glowcolor,1,this.pluginobj.glow,this.pluginobj.glow)); } if(this.pluginobj.blur > 0) { _loc1_.push(new BlurFilter(this.pluginobj.blur,this.pluginobj.blur)); } if(this.pluginobj.shadow > 0) { _loc1_.push(new DropShadowFilter(this.pluginobj.shadow)); } this.bg.filters = _loc1_.length > 0 ? _loc1_ : null; var _loc2_:Array = new Array(); if(this.pluginobj.textglow > 0) { _loc2_.push(new GlowFilter(this.pluginobj.textglowcolor,1,this.pluginobj.textglow,this.pluginobj.textglow)); } if(this.pluginobj.textblur > 0) { _loc2_.push(new BlurFilter(this.pluginobj.textblur,this.pluginobj.textblur)); } if(this.pluginobj.textshadow > 0) { _loc2_.push(new DropShadowFilter(this.pluginobj.textshadow)); } this.txt.filters = _loc2_.length > 0 ? _loc2_ : null; } private function str_replace(param1:String, param2:String, param3:String) : String { var _loc4_:Array = param1.split(param2); return _loc4_.join(param3); } private function updateHTML() : void { var _loc4_:Timer = null; var _loc1_:StyleSheet = new StyleSheet(); var _loc2_:String = this.pluginobj.css; var _loc3_:String = this.pluginobj.html; if(_loc2_ == null || _loc2_ == "") { this.txt.styleSheet = null; } else { if(_loc2_.indexOf("data:") == 0) { _loc2_ = this.krpano.get("data[" + _loc2_.slice(5) + "].content"); } else { _loc2_ = unescape(_loc2_); } _loc1_.parseCSS(_loc2_); this.txt.styleSheet = _loc1_; } if(_loc3_.indexOf("data:") == 0) { _loc3_ = this.krpano.get("data[" + _loc3_.slice(5) + "].content"); } else { _loc3_ = this.str_replace(_loc3_,"[","<"); _loc3_ = this.str_replace(_loc3_,"]",">"); _loc3_ = unescape(_loc3_); } if(_loc3_ == null) { _loc3_ = ""; } this.txt.htmlText = _loc3_; if(this.txt.autoSize != "none") { this.txt_height = this.txt.height; this.pluginobj.height = this.txt_height; _loc4_ = new Timer(0.001,1); _loc4_.addEventListener("timer",this.updateSIZE); _loc4_.start(); } this.pluginobj.textheight = this.txt_height; } private function updateSIZE(param1:TimerEvent = null) : void { this.txt_height = this.txt.height; this.pluginobj.height = this.txt_height; this.pluginobj.textheight = this.txt.textHeight; this.updateSTYLE(); } } }